//
//  AllSpecialListTableViewController.m
//  WisdomZhuHai
//
//  Created by BABLE on 15/4/19.
//  Copyright (c) 2015年 wyd. All rights reserved.
//

#import "AllSpecialListTableViewController.h"
#import "TransforController.h"
#import "TopSpecialDetailsPageTableViewController.h"
#import "Common.h"
#import "ProtocolDefine.h"
#import "TransforController.h"
#import "Common.h"
#import "UIWebControl.h"

const float CELL_HEIGHT = 143;//顶部图片高(和xib一致)

@interface AllSpecialListTableViewController ()
@property (nonatomic,strong)NSArray *newsList;
@end

@implementation AllSpecialListTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[ProtocolManager shareInstance] getAllTopSpecailsWithtarget:self selector:@selector(didFishLangchAllSpecialListTableViewController:)];
    
}

#pragma mark - Table view data source
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    NSDictionary *dic = self.newsList[indexPath.row];
    static NSString *pageCellIdentifier = @"allTopSpecialsImageCell";
    cell = [tableView dequeueReusableCellWithIdentifier:@"CommonBigImageCell"];
    if(cell == nil)
    {
        cell = [[NSBundle mainBundle] loadNibNamed:@"CommonBigImageCell"  owner:self options:nil][0];
    }
    
    UIImageView *topImage = (UIImageView*)[cell viewWithTag:100001];
    [topImage setImageWithURL:[Common getFullDownloadPathByRelativePath:[dic objectForKey:P_ALLTOPICS_MAGEURL]]];

    NSAssert(cell != nil, @"TopSpecialDetailsPageTableViewController cell is nil");
    return cell;
}

-(void)didFishLangchAllSpecialListTableViewController:(NSDictionary *)dic{
    if(dic == nil)
    {
        NSLog(@"didFishLangchAllSpecialListTableViewController dic is nil");
        return ;
    }
    NSArray *ary = [[NSArray alloc] initWithArray:[dic valueForKey:@"topics"]];
    self.newsList = ary;
    UIView *topBar = [TransforController shardeInstanceOfNavigationBarAndStatusBarCoverViewWithY:0 andTitle:@"专题列表"];
    [self.view addSubview:topBar];
    
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 65, self.view.bounds.size.width, self.view.bounds.size.height-65) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    

}


#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row >= self.newsList.count) {
        return;
    }
    NSDictionary* dic = self.newsList[indexPath.row];
    TopSpecialDetailsPageTableViewController *sub =[[TopSpecialDetailsPageTableViewController alloc]init];
    sub.hidesBottomBarWhenPushed = YES;
    sub.topicId = [dic objectForKey:P_ALLTOPICS_GETTOPICID];
    sub.allSpecailsDisShow = [[NSNumber alloc] initWithInt:1];//不创建“全部专题”按钮
//    [self.navigationController pushViewController:sub animated:YES];
    [self.navController pushViewController:sub animated:YES];

}



#pragma mark - Table view default
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{   //CELL尺寸判断器
    return CELL_HEIGHT;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //设置行数
    return self.newsList.count;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}



- (void)pullTableViewDidTriggerRefresh:(PullTableView*)pullTableView{
    
}
- (void)pullTableViewDidTriggerLoadMore:(PullTableView*)pullTableView{
    
}

@end
